package com.thon.entity.user;

// Generated 2013-9-23 19:12:56 by Hibernate Tools 3.4.0.CR1

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.springframework.format.annotation.DateTimeFormat;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.thon.entity.util.IdEntity;

/**
 * MeMessage generated by hbm2java
 */
@Entity
@Table(name = "messages")
@JsonIgnoreProperties(ignoreUnknown = true)
public class Message extends IdEntity {

	private static final long serialVersionUID = 163332541423753784L;
	private User messageTo;
	private User messageFrom;
	private String content;
	private Date readTime;
	private Date createdDate;
	private String action;
	private String fromName;

	public Message() {
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "to_id", nullable = false)
	@JsonIgnoreProperties(value = { "hibernateLazyInitializer", "handler" })
	//@JsonIgnore
	public User getMessageTo() {
		return this.messageTo;
	}

	public void setMessageTo(User messageTo) {
		this.messageTo = messageTo;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "from_id", nullable = false)
	@JsonIgnoreProperties(value = { "hibernateLazyInitializer", "handler" })
	//@JsonIgnore
	public User getMessageFrom() {
		return this.messageFrom;
	}

	public void setMessageFrom(User messageFrom) {
		this.messageFrom = messageFrom;
	}

	public String getContent() {
		return this.content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+08:00")
	public Date getReadTime() {
		return this.readTime;
	}

	public void setReadTime(Date readTime) {
		this.readTime = readTime;
	}

	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+08:00")
	public Date getCreatedDate() {
		return this.createdDate;
	}

	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}

	public String getAction() {
		return this.action;
	}

	public void setAction(String action) {
		this.action = action;
	}

	@Transient
	public String getFromName() {
		return messageFrom.getName();
	}

	public void setFromName(String fromName) {
		this.fromName = fromName;
	}
	

}
